

<template>
  <!--
     读卡 读不到只能新建 所以输入没有必要
     读卡  读到了  就只能修改了
     所以输入是没有必要的
-->
  <div class="addUpdate">
    <ViewTitle text="基础信息" />
    <div class="box1">
      <div class="yisheng">
        <span>病人姓名:</span>
        <selectInput :thatF="this"></selectInput>
      </div>
      <div>
        <span>卡号:</span>
        <el-input
          size="mini"
          disabled
          v-model="setSelectInput.detail.member_info.id_card"
        ></el-input>
      </div>
        <div>
        <span>性别:</span>
        <el-select
          size="mini"
          disabled
          v-model="setSelectInput.detail.member_info.gender"
          placeholder="请选择性别"
        >
          <el-option
            v-for="(item, index) in $baseBai['gender']"
            :key="'index2' + index"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
 
      <div>
        <span>年龄:</span>
        <el-input
          disabled
          size="mini"
          type="number"
          v-model="setSelectInput.detail.member_info.age"
          placeholder="请输入年龄"
        ></el-input>
      </div>
    </div>

    <ViewTitle text="处方信息" />

    <div class="box1">
      <div class="yisheng">
        <span>医生:</span>

        <el-input
          disabled
          size="mini"
          v-model="setSelectInput.detail.doctor_info.real_name"
          ><i slot="suffix" class="el-input__icon el-icon-search"></i
        ></el-input>
      </div>

      <div>
        <span>科室:</span>
        <el-input
          disabled
          size="mini"
          v-model="setSelectInput.detail.doctor_info.dept_name"
        ></el-input>
      </div>

      <div></div>
      <div>
        <span>处方备注:</span>
        <el-input
          type="textarea"
          placeholder="请输入备注"
          v-model="cf_remark"
        >
        </el-input>
      </div>
    </div>

    <div>
      <div class="selects">
        <div class="selectTables">
          <selectv1Input  size="medium" :icon="true" :setSelectInputv1="setSelectInput2"></selectv1Input>
        </div>
        <div style="padding-left: 10px">
            <el-table :data="setSelectInput2.detail" style="width: 100%">
              <template v-for="(item, index) in tableTitle">
                <el-table-column
                  :width="150"
                  v-if="item.prop == 'used_frqu'"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <el-select
                        v-model="scope.row.used_frqu"
                        placeholder="频次"
                      >
                        <el-option
                          v-for="item in pinci"
                          :key="item.name"
                          :label="item.name"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </span>
                  </template>
                </el-table-column>

                <el-table-column
                  v-else-if="item.prop == 'dose'"
                  :width="item.width"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <el-input
                        v-model="scope.row.dose"
                        placeholder="单次剂量"
                      ></el-input>
                    </span>
                  </template>
                </el-table-column>

                <el-table-column
                  :width="item.width"
                  v-else-if="item.prop == 'dose_unit'"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <el-select v-model="scope.row.dose_unit" placeholder="剂量单位">
                        <el-option
                          v-for="item in dose_unit"
                          :key="item.name"
                          :label="item.name"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </span>
                  </template>
                </el-table-column>

                <el-table-column
                  :width="item.width"
                  v-else-if="item.prop == 'usage'"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <el-select v-model="scope.row.usage" placeholder="用法">
                        <el-option
                          v-for="item in geiyao"
                          :key="item.name"
                          :label="item.name"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </span>
                  </template>
                </el-table-column>

                <el-table-column
                  v-else-if="item.prop == 'count'"
                  :width="item.width"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <el-input
                        v-model="scope.row.count"
                        placeholder="数量"
                      ></el-input>
                    </span>
                  </template>
                </el-table-column>

                <el-table-column
                  :width="item.width"
                  v-else-if="item.prop == 'is_skin_test'"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <el-checkbox
                        v-model="scope.row.is_skin_test"
                      ></el-checkbox>
                    </span>
                  </template>
                </el-table-column>
                <el-table-column
                  :width="item.width"
                  v-else-if="item.prop == 'trans_speed'"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <span>
                        <el-select
                          v-model="scope.row.trans_speed"
                          placeholder="滴速"
                        >
                          <el-option
                            v-for="item in disu"
                            :key="item.name"
                            :label="item.name"
                            :value="item.id"
                          >
                          </el-option>
                        </el-select>
                      </span>
                    </span>
                  </template>
                </el-table-column>
                <el-table-column
                  :width="item.width"
                  v-else-if="item.prop == 'usage_extra'"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <el-select
                        v-model="scope.row.usage_extra"
                        placeholder="西药脚注"
                      >
                        <el-option
                          v-for="item in xiyaojiaozhu"
                          :key="item.name"
                          :label="item.name"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </span>
                  </template>
                </el-table-column>

                <el-table-column
                  :width="item.width"
                  v-else-if="item.prop == 'remark'"
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                  <template slot-scope="scope">
                    <span>
                      <span>
                        <el-input
                          v-model="scope.row.remark"
                          placeholder="备注"
                        ></el-input>
                      </span>
                    </span>
                  </template>
                </el-table-column>

                <el-table-column
                  :width="item.width"
                  v-else
                  :prop="item.prop"
                  :label="item.label"
                  :key="index"
                >
                </el-table-column>
              </template>

              <el-table-column fixed="right" label="操作" width="120">
                <template slot-scope="scope">
                  <el-button
                    @click.native.prevent="deleteRow(scope.$index, tableData2)"
                    type="text"
                    size="small"
                  >
                    移除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
        </div>
      </div>
    </div>

    <div style="text-align: center;margin-top: 30px;">
      <el-button class="butB_Add" style="width: 200px" @click="save()"
        >保存</el-button>
    </div>
  </div>
</template>
<script>
let t;
import selectInput from "@/components/select";
import selectv1Input from "@/components/selectv1"
import ViewTitle from "@/forComponents/viewTitle/index.vue";

export default {
  props:['thatF'],
  data() {
    return {
      tableTitle :[],

        disu: [],
      pinci: [],
      geiyao: [],
      dose_unit: [],
       xiyaojiaozhu: [],
      setSelectInput: {
        placeholder: "请选择病人",
        key: "huajia_patient",
        url: "getClinic_doctorRegister_index",
        keyword: "",
        id: "",
        detail: {
          doctor_info: {},
          member_info: {},
        },
        list: [
          { label: "患者姓名", prop: "member_info.name" },
          { label: "门诊号", prop: "patient_no" },
        ],
      },

    setSelectInput2: {
        placeholder: "请选择药品",
        key: "drugs",
        url: "getClinic_doctorgetDrugItem",
        keyword: "",
        id: "",
        detail: [],
        list: [
          { label: "药品", prop: "name" },
          { label: "价格", prop: "price" },
          { label: "规格", prop: "specification" },
        ],
      },
      cf_remark:'',
      paramsUserInfo: {},
      tableData_priceInfo: [],
      patientData: [],
      doctorData: [],
      page: 1,
      limit: 10,
      patientCount: 0,

      doctorPage: 1,
      doctorLimit: 10,
      doctorCount: 0,
      doctorLoading: false,
    };
  },
  mounted() {
    t=this;
     t.tableTitle=t.$baseBai["workstation"]["right_three_table_title"]

     t.getCommonGetPinci()

      Promise.all([
      t.getDict_dataDictIndex('47,12,60'),
      this.getCommonGetPinci(),
      this.getDrug_channelGetList(),
    ]).then((res) => {

      res[0].data.forEach(v => {
          if(v.id==12){
            t.xiyaojiaozhu=v.items
          }else if(v.id==47){
            t.disu = v.items;
          }else if(v.id==60){
            t.dose_unit = v.items;
          }
      });

      t.pinci = res[1].data;
      t.geiyao = res[2].data.list;

    });
  },
  methods: {
      getDict_dataDictIndex(num) {
      let t = this;
      return new Promise((resolve, reject) => {
        t["_API"].getDict_dataDictIndex({ group_id: num }).then((res) => {
          resolve(res);
        });
      });
    },
     getCommonGetPinci() {
      let t = this;
      return new Promise((resolve, reject) => {
        t["_API"].getCommonGetPinci().then((res) => {
          resolve(res);
        });
      });
    },
      getDrug_channelGetList() {
      let t = this;
      return new Promise((resolve, reject) => {
        t["_API"].getDrug_channelGetList().then((res) => {
          resolve(res);
        });
      });
    },
    save() {

      if(!t.setSelectInput.detail.patient_no){
        return   this.$message({
                message: "请选择病人",
                type: "error",
              });
      }
         if(t.setSelectInput2.detail.length<=0){
        return   this.$message({
                message: "请选择药品",
                type: "error",
              });
      }
        let d={
          register_id:t.setSelectInput.detail.id,
          remark:t.cf_remark,
          drug_item:[],

        }

       //添加处方信息

        if (this.setSelectInput2.detail.length >0) {
              this.setSelectInput2.detail.forEach(res=>{
           d.drug_item.push({
             drug_id:res.id,
             unm_unit:res.base_unit,
             num:res.count,
             dose:res.dose,
             dose_unit:res.dose_unit,
             usage:res.usage,
             each_dos:res.used_frqu,
             base_unit:res.base_unit,
             trans_speed:res.trans_speed,
             usage_extra:res.usage_extra,
             is_skin_test:res.is_skin_test?1:0,
             remark:res.remark,

          });
        });
      }

      t._API.getclinic_feeSaveDrugRecipe(d).then(res=>{
        if(res.code==200){
           t.thatF.huajia.show=false;
            this.$message({
                message: res.message,
                type: "success",
              });

        }
        console.log("aaa",res)
      })
    },
  },
  components: {
    ViewTitle,
    selectInput,
    selectv1Input,
    //  FormInfo
  },
};
</script>
<style lang='scss' scoped>
.addUpdate {
  padding: 0 5%;
  .box1 {
    display: flex;
    flex-wrap: wrap;
    padding: 20px 0;
    > div {
      position: relative;
      width: 33%;
      display: flex;
      align-items: center;
      // justify-content: center;
      margin-bottom: 20px;

      > span {
        display: inline-block;
        width: 80px;
      }
      /deep/ .el-input {
        width: 200px;
      }
    }
  }
  .box3 {
    margin: 20px 0;
  }

  .dukaBut {
    margin: 0px 0 20px;
  }
}
/deep/ .el-dialog__body {
  height: 70vh;
  overflow: scroll;
}
// /deep/ .el-table .success-row {
//   background: #02bf6b;
// }

/deep/ .el-table .warning-row {
  background: red;
}

/deep/ .el-table .success-row {
  background: #02bf6b;
}

/deep/ .icon-edit-bai {
  position: absolute;
  right: -32px;
  top: 50%;
  transform: translateY(-50%);
}
.selects {
  position: relative;
  // /deep/ .el-input{
  //   width: 300px;
  // }

  .selectTables {
    width: 300px;
  }
}
</style>
